% Start the program
%function CADX3_EXEC(varargin)

% Clear all the variables loaded
clear;


flag1_1 = false;

ccom_7       = 0;
% Stage counter.
stage1_2 = 0;
% Flag: pull data from main trajectory arrays.
oindat_1      = 0;
% Main trajectory card counter.
oindat_2      = 0;
stage1_1   = 0;
initsubs = 0;
tstage   = 0.0;
prev_1    = 0.0;

%---  Initialize the C array to zeros:

%set_c_zero;

%global C;

%CT = CON();

%---  Setup a default critical value and variable for the non-sweep
%---  runs.   The input deck for sweep runs will reset these variables
%---  to the proper values.  The default variable for the non-sweep
%--   cases is DHJ = 1773.

critno = 1773;
critval = 0.00001;

%     Initialize the max and min plot variable arrays.

%ini1_pmin;

%---  Re- Initialize the common location that contains the number of
%---  variables in the plot list since this value has been zero-ed out
%---  by the above loop.
%nv = nplotvar;

%     Initialize the flag which indicates the action of the EXEC after
%     each integration loop.

kstep   = 1;

C1 = C;

%     Initialize several earth and conversion variables.

CVAR = inil_vars(C1);

% 580 continue;

%---  This section is where the input cards are processed.  The program
%     executes here at the beginning of each trajectory, and returns
%     here at the end of each stage to process the next set of stage cards.


if( CVAR(C1.LCONV) <= 0  )

%         The trajectory has not reached termination as defined by G4
%         module.

%         Perform the input card processing.

%**** UNKNOWN - what this variable does
%oinpt1;

if( CVAR(C1.HMIN) == 0.0 )
    CVAR(C1.HMIN) = CVAR(C1.DER);
end;
if( CVAR(C1.HMAX) == 0.0 )
    CVAR(C1.HMAX) = CVAR(C1.DER);
end;


if( initsubs == 0 )

    %             This is the start of the trajectory computations.
    %             At this point in the code, the variables have been
    %             initialized and the stage 0 cards have been read
    %             and processed.

    %             IF( XSWEEP .AND. MULRUN .EQ. 0 ) THEN

    %                 A Sweep case is being executed (Not with the multi-run
    %                 mode : type 5 card)  Increment the run counter
    %                 here (instead of in the type 21 card processing
    %                 module {prior XR92} ) to keep the count of the number
    %                 of executed trajectories correct.

    %                  JRUN = JRUN + 1
    %              ENDIF

    % 800 continue;

    %     This section performs module initialization.

    %---  Execute the pre-initialization modules for the type 1 card
    %     modules.  NOTE:  Currently no modules defined in this module

    %*** UNKNOWN - this module not needed
    %subl1;


    %---  Call the initialization modules for the type 2 card modules.

    icoor = -2;

    auxi;


    %     Set the flag indicating that the initialization modules have been
    %     executed for this trajectory.

    initsubs = 1;


    %---  Execute the initialization modules for the type 1 cards:
    %     Call the initialization modules for the modules specified on the
    %     input type 1 cards ( OUPT2 and STGE2 )

    %*** UNKNOWN - this module not needed
    %subl2;


    %---  Load the V and DER variables from the C array:
    %     Calculate the number if integration variables defined.

    n  = max( 2, CVAR(C1.NIP) );

    [ n ]=ld_deriv( n );


%             In the middle of a trajectory either through a stage
%             or a type 90 card.  Insure some values of the Executive
%             common/control variables.

end;

end;
